package com.gem.eolane.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gem.eolane.entity.Dict;
import com.gem.eolane.service.DictService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 *  字典工具类
 */
@Component
public class DictUtils {
    @Autowired
    private DictService service;
    private static DictService dictService;

    @PostConstruct  //完成对service的注入
    public void init() {
        dictService = service;
    }
    /**
     * 获取字段值
     */
//    public String getDictValue(String type, Integer value) {
//        Dict dict = dictService.getOne(new QueryWrapper<Dict>()
//                .eq("type",type)
//                .eq("value",value));
//        return dict.getLabel();
//    }

    /**
     * 获取相同字典类集合
     */
    public List<Dict> getDicList(String type) {
        return dictService.valueList(new QueryWrapper<Dict>()
                .eq("type",type));
    }
    /**
     * 获取字典集合
     */
    public List<Dict> getAllDictList() {
        return dictService.valueList(new QueryWrapper());
    }
}
